/**
 * 验证全局变量的共享性
 */


#include <iostream>
#include <pthread.h>

int sharedVar = 0;

void* threadFunc(void* arg) {
    for (int i = 0; i < 5; ++i) {
        ++sharedVar;
        std::cout << "Thread ID: " << pthread_self() 
                  << ", sharedVar: " << sharedVar << std::endl;
    }
    return nullptr;
}

int main() {
    pthread_t t1, t2;
    pthread_create(&t1, nullptr, threadFunc, nullptr);
    pthread_create(&t2, nullptr, threadFunc, nullptr);

    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);
    return 0;
}
